<template>
	<view class="goodslist">
		<goodsList @goodsItemClick="goDetail" :goods="goods"></goodsList>
		<view class="isOver" v-if="flag">
			我是有底线的!!!___
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/good-list/goods-list'
	export default {
		data() {
			return {
				pageindex:1,
				goods:[],
				flag:false
			}
		},
		onReachBottom() {
			
			
			if(this.goods.length<this.pageindex*10) {
				return this.flag=true
			}
			this.pageindex++
			this.getGoodList()
		},
		onPullDownRefresh() {
			console.log(11)
			this.pageindex=1,
			this.goods=[],
			this.flag=false,
			setTimeout(()=>{
				this.getGoodList(()=>{
					uni.stopPullDownRefresh()
				})
			},300)
		},
		components:{
			goodsList
		},
		onLoad() {
			this.getGoodList()
		},
		methods: {
			async getGoodList(callBack){
			let res =await this.$myRequest({
					url:`/api/getgoods?pageindex=${this.pageindex}`
				})
				this.goods=[...this.goods,...res.data.message]
				callBack && callBack()  
			},
			goDetail(id){
				uni.navigateTo({
					url:'/pages/goods-detail/goods-detail?id='+id
				})
			}
		}
	}
</script>

<style lang="less">
	.goodslist{
		background-color: #fabbff;
	}
	.isOver{
		width: 100%;
		height: 50px;
		color: #007AFF;
		text-align: center;
	}
</style>
